<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我要提问</title>
    <script src="jquery.min.js"></script>

</head>
<body>
<div id="head">
    <h1>我要提问</h1>
</div>
<div id="shouye">
  <a href="questions-list.html">返回首页</a>
</div>
<div>
    <form method="get" >
        <p>
            问题：<input type="text" id="title" name="title">
        </p>
        <p>
            问题描述：<input type="text" id="detailDesc" name="detailDesc">
        </p>
        <p>
            问题描述：<input type="submit" id="baocun" value="保存问题">
        </p>
    </form>
</div>

<script>
    $(function () {

       function yanzheng() {
            $("#title").blur(function () {
                if($(this).val()==null||$(this).val()==''){
                    alert("必须填写问题");
                    return;
                }

            });

        }
        yanzheng();
     $("#baocun").click(function () {
        // yanzheng();
       var question=  {title:$("#title").val(),detailDesc:$("#detailDesc").val()};
       alert(JSON.stringify(question));
            $.get("addquestions",question,function (data) {

                if(data.code==0){
                    alert("保存成功");
                }
                   alert("保存失败");
                return false;
            });

        });

    });
</script>
</body>
</html>